<template>
  <div class="app-header-sticky" :class="{show:isSticky}">
    <div class="container">
      <RouterLink class="logo" to="/"/>
      <app-header-nav/>
      <div class="right">
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">专题</RouterLink>
      </div>
    </div>
  </div>
</template>

<script>
import AppHeaderNav from './appHeaderNav'
import { onMounted, ref } from 'vue'

export default {
  name: 'AppHeaderSticky',
  components: { AppHeaderNav },
  setup () {
    /*
        吸顶默认不显示
         滚动到一定距离菜显示
         监听滚动事件
         在滚动事件中获取scrollTop   document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffsetTop
         根据滚动的值判断是否显示吸顶
    */
    const isSticky = ref(false)

    function scrollEvent () {
      const top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      // console.log(top)
      isSticky.value = top > 80

    }

    onMounted(() => {
      window.addEventListener('scroll', scrollEvent)
    })
    return {isSticky}
  }
}
</script>

<style scoped lang='less'>
.app-header-sticky {
  opacity: 0;
  transform: translateY(-100%);
  &.show{
    opacity: 1;
    transform: none;
    transition: all 0.8s;
  }
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;

  .container {
    display: flex;
    align-items: center;
  }

  .logo {
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat right 2px;
    background-size: 160px auto;
  }

  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;

    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;

      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>
